package com.abbas.smartCity.adapter;

import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager2.widget.ViewPager2;

import com.abbas.smartCity.App;
import com.bumptech.glide.Glide;
import com.youth.banner.adapter.BannerAdapter;

import java.util.List;

/**
 * {@link com.youth.banner.adapter.BannerImageAdapter} 是Banner2.0的默认实现
 * @param <T> 数据源类型
 */
@Deprecated
public class BannerCommAdapter<T> extends BannerAdapter<T,BannerCommAdapter.BannerViewHolder> {

    public BannerCommAdapter(List<T> data) {
        super(data);
    }

    @Override
    public BannerViewHolder onCreateHolder(ViewGroup viewGroup, int i) {
        final ImageView imageView = new ImageView(viewGroup.getContext());
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        final ViewGroup.LayoutParams layoutParams = new ViewPager2.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(layoutParams);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(BannerViewHolder bannerViewHolder, T t, int i, int i1) {
        if (t instanceof Integer){
            Glide.with(bannerViewHolder.imageView)
                    .load(t)
                    .into(bannerViewHolder.imageView);
        }else if (t instanceof String){
            Glide.with(bannerViewHolder.imageView)
                    .load(App.getBaseUrl() + t)
                    .into(bannerViewHolder.imageView);
        }
    }

    static class BannerViewHolder extends RecyclerView.ViewHolder{

        private final ImageView imageView;

        public BannerViewHolder(@NonNull ImageView itemView) {
            super(itemView);
            imageView = itemView;
        }
    }

}
